package com.ozo.cloud.gen.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ozo.cloud.common.base.model.*;
import com.ozo.cloud.common.log.annotation.OperateLog;
import com.ozo.cloud.gen.entity.GenColumnMap;
import com.ozo.cloud.gen.pojo.dto.GenColumnMapQueryDTO;
import com.ozo.cloud.gen.pojo.dto.GenColumnMapSaveDTO;
import com.ozo.cloud.gen.service.IGenColumnMapService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 字段类型映射 前端控制器
 * </p>
 *
 * @author qiangesoft
 * @since 2024-11-12
 */
@Tag(name = "字段映射管理")
@RequiredArgsConstructor
@RestController
@RequestMapping("/columnMap")
public class GenColumnMapController {

    private final IGenColumnMapService genColumnMapService;

    @OperateLog(value = "添加字段映射", module = "字段映射")
    @SaCheckPermission("gen:columnMap:add")
    @Operation(summary = "添加字段映射")
    @PostMapping("/add")
    public ResultVO<Void> add(@RequestBody @Valid GenColumnMapSaveDTO saveDTO) {
        genColumnMapService.add(saveDTO);
        return ResultVO.success();
    }

    @OperateLog(value = "删除字段映射", module = "字段映射")
    @SaCheckPermission("gen:columnMap:remove")
    @Operation(summary = "删除字段映射")
    @DeleteMapping("/remove")
    public ResultVO<Void> remove(@RequestBody @Valid BaseBatchDTO<Long> batchDTO) {
        genColumnMapService.remove(batchDTO);
        return ResultVO.success();
    }

    @OperateLog(value = "编辑字段映射", module = "字段映射")
    @SaCheckPermission("gen:columnMap:edit")
    @Operation(summary = "编辑字段映射")
    @PutMapping("/edit")
    public ResultVO<Void> edit(@RequestBody @Validated(value = BaseValidDTO.edit.class)  GenColumnMapSaveDTO saveDTO) {
        genColumnMapService.edit(saveDTO);
        return ResultVO.success();
    }

    @SaCheckPermission("gen:columnMap:page")
    @Operation(summary = "字段映射分页")
    @GetMapping("/page")
    public ResultVO<PageResult<GenColumnMap>> page(@Valid BasePage basePage, GenColumnMapQueryDTO queryDTO) {
        return ResultVO.success(genColumnMapService.page(basePage, queryDTO));
    }

    @Operation(summary = "字段映射列表")
    @GetMapping("/list")
    public ResultVO<List<GenColumnMap>> list(GenColumnMapQueryDTO queryDTO) {
        return ResultVO.success(genColumnMapService.list(queryDTO));
    }

}
